#include "Test.Font.h"

#undef  APP_NAME
#define APP_NAME	TestTextSize
#undef  APP_BASE
#define APP_BASE	TestFont


class APP_NAME : public APP_BASE
{
protected:
	vec2		textDim;
	ext_string	formatted;

public:
	APP_NAME (IPlatform *platform, EDevice::type deviceType) :
		APP_BASE( platform, deviceType )
	{}
	
	void Update (float dt) override
	{
		TestApp::Update( dt );

		ESS()->GetGraphicsEngine()->GetViewport()->Apply();
		ESS()->GetGLStateManager()->Clear( true, true, false );

		rect	text_region = rect(-0.5f, -0.5f, 0.5f, 0.5f );
		rect	text_bounds = rect( text_region.left, text_region.top - textDim.y,
									text_region.left + textDim.x, text_region.top );

		batch.AddBatch( material, Rect2D( text_bounds, rect(), color4u(255, 0, 0, 120) ) );
		fontBatch.Draw( text_region, formatted );

		batch.Flush();
		batch.Clear();
		
		ESS()->GetGraphicsEngine()->SwapBuffers();
	}

	void OnEnter () override
	{
		APP_BASE::OnEnter();

		//text.Parse( "#[align:right]0\n1\n23 456\n\n_789, abc... def\n*" );
		//text.Parse( "#[align:right]0123456789abcdef" );
		//text.Parse( "0 aaa 1 bbbb-22 ccccc 333 dddddd 4" );
		text.Parse( "blablab1lablabl2ablabla3bla" );

		BitmapFontPtr	font = fontBatch.GetFont().To< BitmapFontPtr >();

		LocaleCharacters	lu;

		lu.AddDefaultLatin();

		font->GetFormattedText( fontBatch, 0.7f, text, lu, formatted, textDim );

		string	s;
		formatted.UnParse( s );

		WARNING( s.cstr() );
	}
};
